// System Unit
// UnicodeString Support

(*************)
(* Interface *)
(*************)
{$IFDEF Include_Modules_Header}

 Const
  CodePage_UTF16 = 1200;

 Type
  PUnicodeString = ^UnicodeString;

  UCS2Char = WideChar;
  PUCS2Char = PWideChar;

  UCS4Char = Type LongWord;
  PUCS4Char = ^UCS4Char;
  UCS4String = Array of UCS4Char;

 Function _UStrLen(Const S: UnicodeString): Integer;
 Type RTLProc_UStrLen = Function(Const S: UnicodeString): Integer;

 Function _NewUnicodeString(CharLength: LongInt): Pointer;
 Type RTLProc_NewUnicodeString = Function(CharLength: LongInt): Pointer;

 Procedure _UStrFromPWCharLen(Var Dest: UnicodeString; Source: PWideChar; CharLength: Integer);
 Type RTLProc_UStrFromPWCharLen = Procedure(Var Dest: UnicodeString; Source: PWideChar; CharLength: Integer);

 Procedure _UStrFromWChar(Var Dest: UnicodeString; Source: WideChar);
 Type RTLProc_UStrFromWChar = Procedure(Var Dest: UnicodeString; Source: WideChar);

 Procedure _UStrFromPWChar(Var Dest: UnicodeString; Source: PWideChar);
 Type RTLProc_UStrFromPWChar = Procedure(Var Dest: UnicodeString; Source: PWideChar);

 Procedure _UStrFromWArray(Var Dest: UnicodeString; Source: PWideChar; Length: Integer);
 Type RTLProc_UStrFromWArray = Procedure(Var Dest: UnicodeString; Source: PWideChar; Length: Integer);

 Function _UStrToPWChar(Const S: UnicodeString): PWideChar;
 Type RTLProc_UStrToPWChar = Function(Const S: UnicodeString): PWideChar;

 Procedure _UStrAsg(Var Dest: UnicodeString; Const Source: UnicodeString);
 Type RTLProc_UStrAsg = Procedure(Var Dest: UnicodeString; Const Source: UnicodeString);

 Procedure _UStrLAsg(Var Dest: UnicodeString; Const Source: UnicodeString);
 Type RTLProc_UStrLAsg = Procedure(Var Dest: UnicodeString; Const Source: UnicodeString);

 Function _UniqueStringU(Var Str: UnicodeString): Pointer;
 Type RTLProc_UniqueStringU = Function(Var Str: UnicodeString): Pointer;

 Function _UStrCmp(Const Left, Right: UnicodeString): Integer;
 Type RTLProc_UStrCmp = Function(Const Left, Right: UnicodeString): Integer;

 Function _UStrEqual(Const Left, Right: UnicodeString): Integer;
 Type RTLProc_UStrEqual = Function(Const Left, Right: UnicodeString): Integer;

 Function _UStrAddRef(Str: Pointer): Pointer;
 Type RTLProc_UStrAddRef = Function(Str: Pointer): Pointer;

 Function _UStrClr(Var S): Pointer;
 Type RTLProc_UStrClr = Function(Var S): Pointer;

 Procedure _UStrCat(Var Dest: UnicodeString; Const Source: UnicodeString);
 Type RTLProc_UStrCat = Procedure(Var Dest: UnicodeString; Const Source: UnicodeString);

 Procedure _UStrCat3(Var Dest: UnicodeString; Const Source1, Source2: UnicodeString);
 Type RTLProc_UStrCat3 = Procedure(Var Dest: UnicodeString; Const Source1, Source2: UnicodeString);

 Procedure _UStrCatN(Var Dest: UnicodeString; argCnt: Integer; Const Strs: UnicodeString {...});
 Type RTLProc_UStrCatN = Procedure(Var Dest: UnicodeString; argCnt: Integer; Const Strs: UnicodeString {...});

 Function _UStrCopy(Const S: UnicodeString; Index, Count: Integer): UnicodeString;
 Type RTLProc_UStrCopy = Function(Const S: UnicodeString; Index, Count: Integer): UnicodeString;

 Procedure _UStrDelete(Var S: UnicodeString; Index, Count: Integer);
 Type RTLProc_UStrDelete = Procedure(Var S: UnicodeString; Index, Count: Integer);

 Procedure _UStrInsert(Const Source: UnicodeString; Var Dest: UnicodeString; Index: Integer);
 Type RTLProc_UStrInsert = Procedure(Const Source: UnicodeString; Var Dest: UnicodeString; Index: Integer);

 Procedure _UStrSetLength(Var S: UnicodeString; NewLength: Integer);
 Type RTLProc_UStrSetLength = Procedure(Var S: UnicodeString; NewLength: Integer);

 Procedure _UStrArrayClr(Var StrArray; Count: Integer);
 Type RTLProc_UStrArrayClr = Procedure(Var StrArray; Count: Integer);

 Procedure UniqueString(Var Str: UnicodeString); Inline; Overload;

 //==================
 // RTL Extensions
 //==================
 Type
  TRTLEx_UnicodeString = Record
   _UStrLen: RTLProc_UStrLen;
   _NewUnicodeString: RTLProc_NewUnicodeString;
   _UStrFromPWCharLen: RTLProc_UStrFromPWCharLen;
   _UStrFromWChar: RTLProc_UStrFromWChar;
   _UStrFromPWChar: RTLProc_UStrFromPWChar;
   _UStrFromWArray: RTLProc_UStrFromWArray;
   _UStrToPWChar: RTLProc_UStrToPWChar;
   _UStrAsg: RTLProc_UStrAsg;
   _UStrLAsg: RTLProc_UStrLAsg;
   _UniqueStringU: RTLProc_UniqueStringU;
   _UStrCmp: RTLProc_UStrCmp;
   _UStrEqual: RTLProc_UStrEqual;
   _UStrAddRef: RTLProc_UStrAddRef;
   _UStrClr: RTLProc_UStrClr;
   _UStrCat: RTLProc_UStrCat;
   _UStrCat3: RTLProc_UStrCat3;
   _UStrCatN: RTLProc_UStrCatN;
   _UStrCopy: RTLProc_UStrCopy;
   _UStrDelete: RTLProc_UStrDelete;
   _UStrInsert: RTLProc_UStrInsert;
   _UStrSetLength: RTLProc_UStrSetLength;
   _UStrArrayClr: RTLProc_UStrArrayClr;
  END;

 Procedure RTLExtend_UnicodeString(Var Ex: TRTLEx_UnicodeString);

{$ENDIF Include_Modules_Header}
(******************)
(* Implementation *)
(******************)
{$IFDEF Include_Modules_Implement}

 Function _RTL_UStrLen(Const S: UnicodeString): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_NewUnicodeString(CharLength: LongInt): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrFromPWCharLen(Var Dest: UnicodeString; Source: PWideChar; CharLength: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrFromWChar(Var Dest: UnicodeString; Source: WideChar);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrFromPWChar(Var Dest: UnicodeString; Source: PWideChar);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrFromWArray(Var Dest: UnicodeString; Source: PWideChar; Length: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UStrToPWChar(Const S: UnicodeString): PWideChar;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrAsg(Var Dest: UnicodeString; Const Source: UnicodeString);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrLAsg(Var Dest: UnicodeString; Const Source: UnicodeString);
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UniqueStringU(Var Str: UnicodeString): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UStrCmp(Const Left, Right: UnicodeString): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UStrEqual(Const Left, Right: UnicodeString): Integer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UStrAddRef(Str: Pointer): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UStrClr(Var S): Pointer;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrCat(Var Dest: UnicodeString; Const Source: UnicodeString);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrCat3(Var Dest: UnicodeString; Const Source1, Source2: UnicodeString);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrCatN(Var Dest: UnicodeString; argCnt: Integer; Const Strs: UnicodeString {...});
  ASM
   JMP _INT_NotImplemented
  END;

 Function _RTL_UStrCopy(Const S: UnicodeString; Index, Count: Integer): UnicodeString;
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrDelete(Var S: UnicodeString; Index, Count: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrInsert(Const Source: UnicodeString; Var Dest: UnicodeString; Index: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrSetLength(Var S: UnicodeString; NewLength: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure _RTL_UStrArrayClr(Var StrArray; Count: Integer);
  ASM
   JMP _INT_NotImplemented
  END;

 Procedure UniqueString(Var Str: UnicodeString);
  BEGIN
   _UniqueStringU(Str);
  END;

 Var
  RTL_UStrLen: RTLProc_UStrLen = _RTL_UStrLen;
  RTL_NewUnicodeString: RTLProc_NewUnicodeString = _RTL_NewUnicodeString;
  RTL_UStrFromPWCharLen: RTLProc_UStrFromPWCharLen = _RTL_UStrFromPWCharLen;
  RTL_UStrFromWChar: RTLProc_UStrFromWChar = _RTL_UStrFromWChar;
  RTL_UStrFromPWChar: RTLProc_UStrFromPWChar = _RTL_UStrFromPWChar;
  RTL_UStrFromWArray: RTLProc_UStrFromWArray = _RTL_UStrFromWArray;
  RTL_UStrToPWChar: RTLProc_UStrToPWChar = _RTL_UStrToPWChar;
  RTL_UStrAsg: RTLProc_UStrAsg = _RTL_UStrAsg;
  RTL_UStrLAsg: RTLProc_UStrLAsg = _RTL_UStrLAsg;
  RTL_UniqueStringU: RTLProc_UniqueStringU = _RTL_UniqueStringU;
  RTL_UStrCmp: RTLProc_UStrCmp = _RTL_UStrCmp;
  RTL_UStrEqual: RTLProc_UStrEqual = _RTL_UStrEqual;
  RTL_UStrAddRef: RTLProc_UStrAddRef = _RTL_UStrAddRef;
  RTL_UStrClr: RTLProc_UStrClr = _RTL_UStrClr;
  RTL_UStrCat: RTLProc_UStrCat = _RTL_UStrCat;
  RTL_UStrCat3: RTLProc_UStrCat3 = _RTL_UStrCat3;
  RTL_UStrCatN: RTLProc_UStrCatN = _RTL_UStrCatN;
  RTL_UStrCopy: RTLProc_UStrCopy = _RTL_UStrCopy;
  RTL_UStrDelete: RTLProc_UStrDelete = _RTL_UStrDelete;
  RTL_UStrInsert: RTLProc_UStrInsert = _RTL_UStrInsert;
  RTL_UStrSetLength: RTLProc_UStrSetLength = _RTL_UStrSetLength;
  RTL_UStrArrayClr: RTLProc_UStrArrayClr = _RTL_UStrArrayClr;

 Function _UStrLen(Const S: UnicodeString): Integer;
  ASM
   JMP RTL_UStrLen
  END;

 Function _NewUnicodeString(CharLength: LongInt): Pointer;
  ASM
   JMP RTL_NewUnicodeString
  END;

 Procedure _UStrFromPWCharLen(Var Dest: UnicodeString; Source: PWideChar; CharLength: Integer);
  ASM
   JMP RTL_UStrFromPWCharLen
  END;

 Procedure _UStrFromWChar(Var Dest: UnicodeString; Source: WideChar);
  ASM
   JMP RTL_UStrFromWChar
  END;

 Procedure _UStrFromPWChar(Var Dest: UnicodeString; Source: PWideChar);
  ASM
   JMP RTL_UStrFromPWChar
  END;

 Procedure _UStrFromWArray(Var Dest: UnicodeString; Source: PWideChar; Length: Integer);
  ASM
   JMP RTL_UStrFromWArray
  END;

 Function _UStrToPWChar(Const S: UnicodeString): PWideChar;
  ASM
   JMP RTL_UStrToPWChar
  END;

 Procedure _UStrAsg(Var Dest: UnicodeString; Const Source: UnicodeString);
  ASM
   JMP RTL_UStrAsg
  END;

 Procedure _UStrLAsg(Var Dest: UnicodeString; Const Source: UnicodeString);
  ASM
   JMP RTL_UStrLAsg
  END;

 Function _UniqueStringU(Var Str: UnicodeString): Pointer;
  ASM
   JMP RTL_UniqueStringU
  END;

 Function _UStrCmp(Const Left, Right: UnicodeString): Integer;
  ASM
   JMP RTL_UStrCmp
  END;

 Function _UStrEqual(Const Left, Right: UnicodeString): Integer;
  ASM
   JMP RTL_UStrEqual
  END;

 Function _UStrAddRef(Str: Pointer): Pointer;
  ASM
   JMP RTL_UStrAddRef
  END;

 Function _UStrClr(Var S): Pointer;
  ASM
   JMP RTL_UStrClr
  END;

 Procedure _UStrCat(Var Dest: UnicodeString; Const Source: UnicodeString);
  ASM
   JMP RTL_UStrCat
  END;

 Procedure _UStrCat3(Var Dest: UnicodeString; Const Source1, Source2: UnicodeString);
  ASM
   JMP RTL_UStrCat3
  END;

 Procedure _UStrCatN(Var Dest: UnicodeString; argCnt: Integer; Const Strs: UnicodeString {...});
  ASM
   JMP RTL_UStrCatN
  END;

 Function _UStrCopy(Const S: UnicodeString; Index, Count: Integer): UnicodeString;
  ASM
   JMP RTL_UStrCopy
  END;

 Procedure _UStrDelete(Var S: UnicodeString; Index, Count: Integer);
  ASM
   JMP RTL_UStrDelete
  END;

 Procedure _UStrInsert(Const Source: UnicodeString; Var Dest: UnicodeString; Index: Integer);
  ASM
   JMP RTL_UStrInsert
  END;

 Procedure _UStrSetLength(Var S: UnicodeString; NewLength: Integer);
  ASM
   JMP RTL_UStrSetLength
  END;

 Procedure _UStrArrayClr(Var StrArray; Count: Integer);
  ASM
   JMP RTL_UStrArrayClr
  END;

 //==================
 // RTL Extensions
 //==================

 Procedure RTLExtend_UnicodeString(Var Ex: TRTLEx_UnicodeString);
  BEGIN
   _INT_RTL_DoEx(@RTL_UStrLen, @Ex._UStrLen);
   _INT_RTL_DoEx(@RTL_NewUnicodeString, @Ex._NewUnicodeString);
   _INT_RTL_DoEx(@RTL_UStrFromPWCharLen, @Ex._UStrFromPWCharLen);
   _INT_RTL_DoEx(@RTL_UStrFromWChar, @Ex._UStrFromWChar);
   _INT_RTL_DoEx(@RTL_UStrFromPWChar, @Ex._UStrFromPWChar);
   _INT_RTL_DoEx(@RTL_UStrFromWArray, @Ex._UStrFromWArray);
   _INT_RTL_DoEx(@RTL_UStrToPWChar, @Ex._UStrToPWChar);
   _INT_RTL_DoEx(@RTL_UStrAsg, @Ex._UStrAsg);
   _INT_RTL_DoEx(@RTL_UStrLAsg, @Ex._UStrLAsg);
   _INT_RTL_DoEx(@RTL_UniqueStringU, @Ex._UniqueStringU);
   _INT_RTL_DoEx(@RTL_UStrCmp, @Ex._UStrCmp);
   _INT_RTL_DoEx(@RTL_UStrEqual, @Ex._UStrEqual);
   _INT_RTL_DoEx(@RTL_UStrAddRef, @Ex._UStrAddRef);
   _INT_RTL_DoEx(@RTL_UStrClr, @Ex._UStrClr);
   _INT_RTL_DoEx(@RTL_UStrCat, @Ex._UStrCat);
   _INT_RTL_DoEx(@RTL_UStrCat3, @Ex._UStrCat3);
   _INT_RTL_DoEx(@RTL_UStrCatN, @Ex._UStrCatN);
   _INT_RTL_DoEx(@RTL_UStrCopy, @Ex._UStrCopy);
   _INT_RTL_DoEx(@RTL_UStrDelete, @Ex._UStrDelete);
   _INT_RTL_DoEx(@RTL_UStrInsert, @Ex._UStrInsert);
   _INT_RTL_DoEx(@RTL_UStrSetLength, @Ex._UStrSetLength);
   _INT_RTL_DoEx(@RTL_UStrArrayClr, @Ex._UStrArrayClr);
  END;

{$ENDIF Include_Modules_Implement}
(******************)
(* Initialization *)
(******************)
{$IFDEF Include_Modules_Initialize}
{$ENDIF Include_Modules_Initialize}
(****************)
(* Finalization *)
(****************)
{$IFDEF Include_Modules_Finalize}
{$ENDIF Include_Modules_Finalize}
